#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/2/25 21:50
# @Author  : jize.liu
# @File    : Check_MultipleNamespace.py
# @声明     : 版权由 刘继泽 所有,如有疑问，需要帮助请联系刘继泽
import maya.cmds as cmds
import os

class Check_MultipleNamespace():
    def Check_MultipleNamespace(self) :
        log = ''
        #RfNodes = cmds.ls (rf=True)
        RfNodes = cmds.file (q = True , r = True)
        for RfNode in RfNodes :
            try:
                if cmds.referenceQuery (RfNode, isLoaded=True):
                    print(RfNode)
                    nameSPace = cmds.referenceQuery (RfNode, namespace=True)
                    TmpArray = nameSPace.split (":")
                    TmpArray = [item for item in TmpArray if item]

                    if len (TmpArray) > 1 :
                        if cmds.namespace (exists=TmpArray[0]) :
                            cmds.namespace (f=True, mv=(TmpArray[0], ":"))
                            cmds.namespace (f=True, rm=TmpArray[0])
                            self.Check_MultipleNamespace()
                            log += nameSPace + "-YES,"
            except Exception as e :
                log += str (e)
                return (log)


        '''
        nameSpace = cmds.namespaceInfo (lon=1)
        nameSpace.remove ("UI")
        nameSpace.remove ("shared")
        referenceRefNode = cmds.ls (rf=1, rn=1)

        referenceNode = cmds.ls (rf=1)
        namespacelist = []
        tmpNamespace = []
        tmpNodeList = []
        over = 1
        # print referenceNode
        referenceNode = list (set (referenceRefNode) ^ set (referenceNode))
        for tmp in referenceNode :
            tmpNodeList = cmds.referenceQuery (tmp, nodes=1)
            print (tmpNodeList)

            tmpNamespace = tmpNodeList[0].split (":")
            # print tmpNamespace
            namespacelist.append (tmpNamespace[len (tmpNamespace) - 2])
        for tmp in nameSpace :
            if tmp not in namespacelist :
                cmds.namespace (f=1, mv=[tmp, ":"])
                cmds.namespace (rm=tmp)
                log += tmp + "-YES,"
            else:
                log += tmp + "-NO,"
        '''
        return (log)



